package com.guofen.controller.cylj;

import com.guofen.pojo.KitchenwasteDischarge;
import com.guofen.service.cylj.KitchenwasteDischargeService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api("厨余垃圾黑水虻就地处理站出料记录表")
public class KitchenwasteDischargeController {
    @Resource
    private KitchenwasteDischargeService kitchenwasteDischargeService;

    @ApiOperation("提交厨余垃圾黑水虻就地处理站出料记录")
    @PostMapping("/kitchenwaste/discharge/add")
    public boolean submitAllInfo(@RequestParam("dischargeDate") String dischargeDate, @RequestParam("incomeDate") String incomeDate, @RequestParam("cabinetNumber") String cabinetNumberstr,
                                 @RequestParam("layerNumber") String layerNumberstr, @RequestParam("insectDungWeight") String insectDungWeightstr, @RequestParam("insectWeight") String insectWeightstr,
                                 @RequestParam("recorder") String recorder, @RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        Integer cabinetNumber = Integer.parseInt(cabinetNumberstr);
        Integer layerNumber = Integer.parseInt(layerNumberstr);
        Double insectDungWeight = Double.parseDouble(insectDungWeightstr);
        Double insectWeight  = Double.parseDouble(insectWeightstr);
        return kitchenwasteDischargeService.submitAllInfo(new KitchenwasteDischarge(dischargeDate,incomeDate,cabinetNumber,layerNumber,insectDungWeight,insectWeight,recorder,remark));
    }
    @ApiOperation("获取 当日 最新 一条记录")
    @GetMapping(value = "/kitchenwaste/discharge/getlast")
    public Result getlast(){
        return  ResultGenerator.genSuccessResult(kitchenwasteDischargeService.getlast());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/kitchenwaste/discharge/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(kitchenwasteDischargeService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/kitchenwaste/discharge/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "dischargeDate", value = "出料时间", required = true) @RequestParam String dischargeDate,
                         @ApiParam(name = "incomeDate", value = "进料时间", required = true) @RequestParam String incomeDate,
                         @ApiParam(name = "cabinetNumber", value = "柜数", required = true) @RequestParam String cabinetNumber,
                         @ApiParam(name = "layerNumber", value = "层数", required = true) @RequestParam String layerNumber,
                         @ApiParam(name = "insectDungWeight", value = "虫粪", required = true) @RequestParam String insectDungWeight,
                         @ApiParam(name = "insectWeight", value = "虫", required = true) @RequestParam String insectWeight,
                         @ApiParam(name = "remark", value = "备注", required = false) @RequestParam String remark) {

        Integer CN = Integer.parseInt(cabinetNumber);
        Integer LN = Integer.parseInt(layerNumber);
        Double IDW = Double.parseDouble(insectDungWeight);
        Double IW  = Double.parseDouble(insectWeight);
        return ResultGenerator.genSuccessResult(kitchenwasteDischargeService.update(new KitchenwasteDischarge(id,dischargeDate,incomeDate
        ,CN,LN,IDW,IW,null,remark)));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/kitchenwaste/discharge/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(kitchenwasteDischargeService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(kitchenwasteDischargeService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
